package a2;

import javax.swing.JFrame;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 * Title: RectangleGUI class for CSIS 235 Assignment #2
 * Description: CS 235 Assignment #2
 *    Basic GUI class that draws Rectangle objects.
 * 
 * @author Anthony Varghese
 * @email anthony.varghese@my.uwrf.edu
 * @author 
 * @email 
 * @author 
 * @email 
 * @author 
 * @email 
 * @date Sept
 * @version 1.0
 */

public class RectangleGUI extends JFrame {

	/**
	 * main - this is where the program starts
	 * @param args
	 */
	public static void main(String[] args) {
		new RectangleGUI("Rectangles");

	}

	/**
	 * Class data members:
	 * Default serial version id
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Instance data members
	 */
	private RectangleArray rectangles;

	/**
	 * Constructor with a String to be used as the title
	 * @param string
	 */
	public RectangleGUI(String title) {
		setTitle( title );
		final int X_SIZE = 400;
		final int Y_SIZE = 300;
		setBounds( 100, 100, X_SIZE, Y_SIZE);
		
		final int NRECTANGLES = 1000;
		rectangles = new RectangleArray( NRECTANGLES );
		
		int y2 = (int)(Y_SIZE * Math.random() );
		rectangles.add( new Rectangle( 10, 30, 200, y2 ) );
		Color c = new Color( /* red = */    128, 
							 /* green = */   64, 
							 /* blue = */   200 );
		rectangles.add( new Rectangle( 100, 200, 20, 76, c ) );

		rectangles.add( new Square( 50, 70, 100, Color.CYAN ) );
		rectangles.add( new Square( 55 ) );
		

		setDefaultCloseOperation( EXIT_ON_CLOSE );
		setVisible(true);
	}

	/**
	 * 
	 * paint method - this gets called whenever the window has to be "refreshed"
	 * Notice that it is not called anywhere in this program.
	 * 
	 * @see java.awt.Window#paint(java.awt.Graphics)
	 */
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g;
		
		rectangles.draw( g2d );
	}

}
